package cn.tkb.org.controller;
import cn.tkb.basic.util.AjaxResult;
import cn.tkb.basic.util.PageQuery;
import cn.tkb.org.domain.SystemLog;
import cn.tkb.org.query.LogQuery;
import cn.tkb.org.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/log")
public class SysyemLogController {
    @Autowired
    private ILogService logService;
    //查询日志
    @GetMapping("/{id}")
    public SystemLog queryById(@PathVariable("id") Long id){
        return logService.QeuryById(id);
    }
    //删除日志
    @DeleteMapping("/{id}")
        public AjaxResult deleteById(@PathVariable("id") Long id){
        try {
            logService.delete(id);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("删除失败");
        }

    }
    //批量删除
    @PatchMapping
    public AjaxResult BatchDelete(@RequestBody List<Long> ids){
        try {
            logService.BatchDelete(ids);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return  AjaxResult.fail(e.getMessage());
        }
    }
    //查询所有日志
    @GetMapping
    public List<SystemLog> queryAll(){
        return logService.QeuryAll();
    }
    //高级查询和分页查询
    @PostMapping
    public PageQuery<SystemLog> queryPage(@RequestBody LogQuery query){
       return logService.findPage(query) ;
    }
}
